Function.prototype.myApply = function (ctx) {
    ctx = ctx || window
    ctx.fn = this //this是当前调用函数

    console.log("this", this);

    let args = arguments[1] || []
    let result = ctx.fn(...args)
    delete ctx.fn
    return result
}

function add(a, b) {
    console.log("我执行了");
    return a + b;
}
function sub(a, b) {
    return a - b;
}

var a1 = add.myApply(sub, [4, 2]);　　//sub调用add的方法
// var a2 = sub.myApply(add, [4, 2]);


console.log(a1);
// console.log(a2);